import { isQueue, _rotate2 } from '../math/index.js'
import { newSeq } from '../math/arraySort.js'

// 单位正方形
// 顺时针
export const unitSquare = [[1, -1], [-1, -1], [-1, 1], [1, 1]]
// 逆时针
const unitSquareSweep = [[1, -1], [1, 1], [-1, 1], [-1, -1]]
// [[-1, 1], [1, 1], [1, -1], [-1, -1]]
// 放大缩小
// 支持多点围绕中点旋转
export const _unitScale = (p, radio, a) => {
    if (isQueue(p)) {
        if (a) {
            p = _rotate2(p, a)
        }
        return p.map(t => _unitScale(t, radio))
    }
    return [p[0] * radio, p[1] * radio]
}


// 线段平移
export const _unitMove = (p, to, radio, a) => {
    if (isQueue(p)) {
        if (radio) {
            let points = _unitScale(p, radio, a)
            return _unitMove(points, to)
        }
        return p.map(t => _unitMove(t, to))
    } else {
        return [p[0] + to[0], p[1] + to[1]]
    }
}

export const _squarePoints = (o, r, sweep, startIndex,a) => {
    let arr = [...(sweep ? unitSquareSweep : unitSquare)]
    if (startIndex) {
        arr = newSeq(arr, startIndex)
    }
    return _unitMove(arr, o, r,a)
}

// 2x2
// _squarePoints
// 4x4
export const _squarePoints4_4 = (o, r) => {
    let arr = _squarePoints(o, r)
    return arr.map(t => _squarePoints(t, r / 2))
}
